import { ref } from 'vue';
import router from '@/router';

// 全局状态管理 - 用户认证信息
const userStore = {
  userId: ref(localStorage.getItem('userId') || null),
  isAuthenticated() {
    return !!this.userId.value;
  },
  setUserInfo(userInfo) {
    this.userId.value = userInfo.userId;
    localStorage.setItem('userId', userInfo.userId);
  },
  logout() {
    localStorage.removeItem('userId');
    this.userId.value = null;
    router.push('/login');
  }
};

export default userStore;